package com.project.springboot.goodcode.simplebuilder;

/**
 * description: 电脑实体类（简单构造者模式）
 * @author 朱正磊
 * @date 2024-09-19 09:08:20
 */
public class Computer {

    // 必须
    private final String cpu;
    // 必须
    private final String ram;
    // 可选
    private final int usbCount;
    // 可选
    private final String keyboard;
    // 可选
    private final String display;

    private Computer(Builder builder) {
        this.cpu = builder.cpu;
        this.ram = builder.ram;
        this.usbCount = builder.usbCount;
        this.keyboard = builder.keyboard;
        this.display = builder.display;
    }

    public static class Builder {

        // 必须
        private final String cpu;
        // 必须
        private final String ram;
        // 可选
        private int usbCount;
        // 可选
        private String keyboard;
        // 可选
        private String display;

        public Builder(String cpu, String ram) {
            this.cpu = cpu;
            this.ram = ram;
        }

        public Builder setUsbCount(int usbCount) {
            this.usbCount = usbCount;
            return this;
        }

        public Builder setKeyboard(String keyboard) {
            this.keyboard = keyboard;
            return this;
        }

        public Builder setDisplay(String display) {
            this.display = display;
            return this;
        }

        public Computer build() {
            return new Computer(this);
        }

    }

    @Override
    public String toString() {
        return "Computer{" +
                "cpu='" + cpu + '\'' +
                ", ram='" + ram + '\'' +
                ", usbCount=" + usbCount +
                ", keyboard='" + keyboard + '\'' +
                ", display='" + display + '\'' +
                '}';
    }

    public String toString2() {
        return "Computer{" +
                "cpu='" + cpu + "'" +
                ", ram='" + ram + "'" +
                ", usbCount=" + usbCount +
                ", keyboard='" + keyboard + "'" +
                ", display='" + display + "'" +
                "}";
    }

    public String toString3() {
        return "Computer{" +
                "cpu='" + cpu +
                "', ram='" + ram +
                "', usbCount=" + usbCount +
                ", keyboard='" + keyboard +
                "', display='" + display +
                "'}";
    }

}
